package org.zjt.platform.springbootreactivedemo.config.endpoint;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.boot.logging.LogLevel;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;

/**
 * Description:
 *
 * @author juntao.zhang
 * Date: 2018-06-13 上午10:34
 *
 * {@link ControllerEndpoint} 并且 {@link RestControllerEndpoint}可以用于实现仅由Spring MVC或Spring WebFlux公开的端点。
 * 使用Spring MVC和Spring WebFlux的标准注释（例如@RequestMapping 和）来映射方法@GetMapping，并将端点ID用作路径的前缀。
 * 控制器端点提供了与Spring的Web框架的更深层次的集成，但代价是可移植性。的 {@link Endpoint}和 {@link WebEndpoint}注解应当优选只要有可能。
 *
 * <a href = "https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-endpoints">官方文档1</a>
 * {@link DeleteOperation}
 */

@Component
@WebEndpoint(id = "my-endpoint")
@Slf4j
public class CustomizedEndpoint{

    @ReadOperation(produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public Mono<String> hello() {
        return Mono.just("<h1>hello endpoint</h1>");
    }

    @WriteOperation
    public Mono<String> postMethod(@Selector String name,
                                  @Nullable Integer age) {
        log.info("-----------configureLogLevel--------- name:{}    age:{}",name,age);

        return Mono.just("<h1>WriteOperation  is http post</h1>");
    }

}
